using Microsoft.EntityFrameworkCore;
using BookApi.Data;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
//添加MVC服务
builder.Services.AddControllers();

//获取数据库连接字符串连接字符串
var connectionString = builder.Configuration.GetConnectionString("mysql");

//注册数据库上下文
builder.Services.AddDbContext<ApiDbContext>(x =>
{
    // ServerVersion.AutoDetect(connectionString): 自动识别你的数据库版本
    x.UseMySql(connectionString, ServerVersion.AutoDetect(connectionString));
});


var app = builder.Build();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
    app.UseSwagger();
    app.UseSwaggerUI();
}

//配置中间件
app.UseRouting();
app.MapControllers();

app.Run();